SELECT * FROM (SELECT c1, c2, lead(c1) OVER ( PARTITION BY c2 ORDER BY c1) lead_c1, lag(c1) OVER ( PARTITION BY c2 ORDER BY c1) lag_c1, ntile(3) OVER ( PARTITION BY c2 ORDER BY c1) tile, first_value(c1) OVER ( PARTITION BY c2 ORDER BY c1) firstVal_c1, last_value(c1) OVER ( PARTITION BY c2 ORDER BY c1) lastVal_c1 FROM "tblWnulls.parquet") sub_query ORDER BY tile, c1